﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.UI;
using System.IO;

namespace Helpers.UIHelpers
{
    class Grid
    {
    }
    public static class GridHelper
    {
        public static MvcHtmlString Grid<T>(this HtmlHelper helper)
        {
            return Grid<T>(helper, null, null);
        }
        public static MvcHtmlString Grid<T>(this HtmlHelper helper, IEnumerable<object> data)
        {
            return Grid<T>(helper, data, null);
        }
        public static MvcHtmlString Grid<T>(this HtmlHelper helper, IEnumerable<object> data, string[] columns)
        {
            //Get column names
            if (columns == null)
                columns = typeof(T).GetProperties().Select(p => p.Name).ToArray();

            HtmlTextWriter htmlWriter = new HtmlTextWriter(new StringWriter());
            //begin table
            htmlWriter.RenderBeginTag(HtmlTextWriterTag.Table);
            // begin tr
            htmlWriter.RenderBeginTag(HtmlTextWriterTag.Tr);

            foreach (var columnName in columns)
            {
                // begin th
                htmlWriter.RenderBeginTag(HtmlTextWriterTag.Th);

                // content
                htmlWriter.Write("adfasdf");


                // end th
                htmlWriter.RenderEndTag();
            }

            // end tr
            htmlWriter.RenderEndTag();
            //end table
            htmlWriter.RenderEndTag();
            htmlWriter.Write("adfasdf");
            return new MvcHtmlString(htmlWriter.InnerWriter.ToString());
        }
    }
}
